ioemu: Share framebuffer between VGA device model and VNC server.
authorKeir Fraser <keir.fraser@citrix.com>
Wed, 20 Feb 2008 17:47:58 +0000 (17:47 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Wed, 20 Feb 2008 17:47:58 +0000 (17:47 +0000)
Now that the qemu WMVi patch is applied we can take full advantage of
it sharing the video buffer between the vga driver and the qemu vnc
server. This saves a lot of memcpy. It's worth mentioning again that
when the guest colour depth is 24 bit we cannot share the buffer
because 24 bpp is not supported by the vnc protocol, so we still have
to do the translation 24 bpp -> 32 bpp.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
tools/ioemu/hw/vga.c
tools/ioemu/vl.h
tools/ioemu/vnc.c

index 4e2f9525a79aec60053db762d98f91dc6716e817..7c627166422d6f6a750a59c074fb03612814100c 100644 (file)
@@ -1135,8 +1135,6 @@ static void vga_draw_text(VGAState *s, int full_update)
     }
 
     depth = s->get_bpp(s);
-    if (depth == 24)
-        depth = 32;
     if (s->ds->dpy_colourdepth != NULL && s->ds->depth != depth)
         s->ds->dpy_colourdepth(s->ds, depth);
     if (width != s->last_width || height != s->last_height ||
@@ -1557,10 +1555,10 @@ static void vga_draw_graphic(VGAState *s, int full_update)
     vga_draw_line = vga_draw_line_table[v * NB_DEPTHS + get_depth_index(s->ds)];
 
     depth = s->get_bpp(s);
-    if (depth == 24)
-        depth = 32;
-    if (s->ds->dpy_colourdepth != NULL && s->ds->depth != depth)
-        s->ds->dpy_colourdepth(s->ds, depth);
+    if (s->ds->dpy_colourdepth != NULL && s->ds->depth != depth) {
+        if (depth != 24 || s->ds->depth != 32)
+            s->ds->dpy_colourdepth(s->ds, depth);
+    }
     if (disp_width != s->last_width ||
         height != s->last_height) {
         dpy_resize(s->ds, disp_width, height);
@@ -1570,7 +1568,9 @@ static void vga_draw_graphic(VGAState *s, int full_update)
         s->last_height = height;
         full_update = 1;
     }
-    if (s->cursor_invalidate)
+    if (s->ds->shared_buf && s->ds->data != s->vram_ptr + (s->start_addr * 4))
+        s->ds->data = s->vram_ptr + (s->start_addr * 4);
+    if (!s->ds->shared_buf && s->cursor_invalidate)
         s->cursor_invalidate(s);
     
     line_offset = s->line_offset;
@@ -1621,9 +1621,11 @@ static void vga_draw_graphic(VGAState *s, int full_update)
                 page_min = page0;
             if (page_max == 0 || page1 > page_max)
                 page_max = page1;
-            vga_draw_line(s, d, s->vram_ptr + addr, width);
-            if (s->cursor_draw_line)
-                s->cursor_draw_line(s, d, y);
+            if (!s->ds->shared_buf) {
+                vga_draw_line(s, d, s->vram_ptr + addr, width);
+                if (s->cursor_draw_line)
+                    s->cursor_draw_line(s, d, y);
+            }
         } else {
             if (y_start >= 0) {
                 /* flush to display */
index ae691b6131d29154c6b72b05b62a9eee38ccd6c0..2efa0112df9d94364e8fbfa348fe0ae0eb055910 100644 (file)
@@ -935,6 +935,7 @@ struct DisplayState {
     void *opaque;
 
     int switchbpp;
+    int shared_buf;
     
     void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
     void (*dpy_resize)(struct DisplayState *s, int w, int h);
index 7f87f8ed189ae8bade68b4df7b8ac125ec14084c..60174070ca637f2afbc9100487a2da0d55158b1f 100644 (file)
@@ -336,11 +336,21 @@ static void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h,
 
 static void vnc_dpy_resize(DisplayState *ds, int w, int h)
 {
+    static int allocated;
     int size_changed;
     VncState *vs = ds->opaque;
     int o;
 
-    ds->data = realloc(ds->data, w * h * vs->depth);
+    if (!ds->shared_buf) {
+        if (allocated)
+            ds->data = realloc(ds->data, w * h * vs->depth);
+        else
+            ds->data = malloc(w * h * vs->depth);
+        allocated = 1;
+    } else if (allocated) {
+        free(ds->data);
+        allocated = 0;
+    }
     vs->old_data = realloc(vs->old_data, w * h * vs->depth);
     vs->dirty_row = realloc(vs->dirty_row, h * sizeof(vs->dirty_row[0]));
     vs->update_row = realloc(vs->update_row, h * sizeof(vs->dirty_row[0]));
@@ -538,6 +548,11 @@ static void vnc_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int dst_
     VncState *vs = ds->opaque;
     int updating_client = 1;
 
+    if (ds->shared_buf) {
+        framebuffer_set_updated(vs, dst_x, dst_y, w, h);
+        return;
+    }
+
     if (src_x < vs->visible_x || src_y < vs->visible_y ||
        dst_x < vs->visible_x || dst_y < vs->visible_y ||
        (src_x + w) > (vs->visible_x + vs->visible_w) ||
@@ -1409,9 +1424,6 @@ static void set_pixel_format(VncState *vs,
     vs->blue_shift = blue_shift;
     vs->blue_max = blue_max;
     vs->pix_bpp = bits_per_pixel / 8;
-
-    vga_hw_invalidate();
-    vga_hw_update();
 }
 
 static void pixel_format_message (VncState *vs) {
@@ -1468,16 +1480,26 @@ static void pixel_format_message (VncState *vs) {
 static void vnc_dpy_colourdepth(DisplayState *ds, int depth)
 {
     int host_big_endian_flag;
-    struct VncState *vs;
-    
-    if (!depth) return;
-    
+    struct VncState *vs = ds->opaque;
+
+    switch (depth) {
+        case 24:
+            ds->shared_buf = 0;
+            depth = 32;
+            break;
+        case 0:
+            ds->shared_buf = 0;
+            return;
+        default:
+            ds->shared_buf = 1;
+            break;
+    }
+
 #ifdef WORDS_BIGENDIAN
     host_big_endian_flag = 1;
 #else
     host_big_endian_flag = 0;
-#endif
-    vs = ds->opaque;   
+#endif   
     
     switch (depth) {
         case 8:
@@ -2312,7 +2334,7 @@ void vnc_display_init(DisplayState *ds)
 
     vs->ds->width = 640;
     vs->ds->height = 400;
-    vnc_dpy_colourdepth(vs->ds, 32);
+    vnc_dpy_colourdepth(vs->ds, 24);
 }
 
 #if CONFIG_VNC_TLS